home *** CD-ROM | disk | FTP | other *** search
- Path: rcogate.rco.qc.ca!altitude!obelix
- From: dtaylor@pifus.com (David Taylor)
- Newsgroups: comp.lang.c++
- Subject: Re: Compiler Bug - can call private constructors.
- Date: Wed, 14 Feb 96 13:40:44 GMT
- Organization: Pifus Inc.
- Message-ID: <4fsork$bef@tandem.CAM.ORG>
- References: <311a149f.8353477@hector> <4fnk8n$17e@daffodil.InfoChan.COM>
- NNTP-Posting-Host: pifus.hip.cam.org
- X-Newsreader: News Xpress 2.0 Beta #0
-
- In article <4fnk8n$17e@daffodil.InfoChan.COM>, alanj@infochan.com (Alan Johnston) wrote:
- >Kenn@owl-uk.co.uk (Ken Nicolson) wrote:
- >>>>>> SAMPLE CODE REPRODUCING PROBLEM
- >
- >>#include <stdio.h>
- >>#include <iostream.h>
- >
- >>class FOOBAR
- >>{
- >>private:
- >> FOOBAR()
- >> {
- >> cout << "I've called a private constructor!\n";
- >> }
- >>};
- >
- >
- >>FOOBAR foobar()
- >>{
- >>// FOOBAR b; SYNTAX ERROR, as expected
- >> return FOOBAR( ); // This is wrong
- >>}
- >
- >Perhaps the problem stems from the fact that 'return FOOBAR() '
- >actually calls the copy constructor. Since you haven't declared a
- >private copy constructor, the compiler is making one for you, and it
- >is public. Try declaring a private copy constructor:
- >FOOBAR(const FOOBAR&);
- >
-
- Actually, would not the default constructor be called first, creating a
- temporary, and then the temporary passed to the copy constructor to complete
- the return call? After all, the copy constructor needs something to copy.
-
- Dave
- dtaylor@pifus.com
-